function fig = fm_pmufig()
% FM_PMUFIG create GUI for PMU placements
%
% FM_PMUFIG()
%
%Author:    Federico Milano
%Date:      11-Nov-2002
%Version:   1.0.0
%
%E-mail:    federico.milano@ucd.ie
%Web-site:  faraday1.ucd.ie/psat.html
%
% Copyright (C) 2002-2019 Federico Milano

global Theme Path Fig Settings PMU

if ishandle(Fig.pmu), figure(Fig.pmu), return, end
if ~Settings.init
  fm_disp('Solve Power Flow for running PMU placement.')
  return
end

loc_method = {'Depth First'; 'Graph Theor. Proc.'; 'Annealing Method'; ...
              'Rec. Spanning Tree';'Dir. Spanning Tree'; ...
              'Rec. (N-1) Spanning Tree'; 'Dir. (N-1) Spanning Tree'};

h0 = figure('Color',Theme.color01, ...
            'Units', 'normalized', ...
            'Colormap',[], ...
            'CreateFcn','Fig.pmu = gcf;', ...
            'DeleteFcn','Fig.pmu = -1;', ...
            'FileName','fm_pmufig', ...
            'MenuBar','none', ...
            'Name','Linear Static State Estimation', ...
            'NumberTitle','off', ...
            'PaperPosition',[18 180 576 432], ...
            'PaperUnits','points', ...
            'Position',sizefig(0.5641,0.5488), ...
            'ToolBar','none');

% Menu File
h1 = uimenu('Parent',h0, ...
            'Label','File', ...
            'Tag','MenuFile');
h2 = uimenu('Parent',h1, ...
            'Callback','fm_pmuloc;', ...
            'Label','Run', ...
            'Tag','OTV', ...
            'Accelerator','z');
h2 = uimenu('Parent',h1, ...
            'Callback','fm_pmun1;', ...
            'Label','Run N-1', ...
            'Tag','OTV', ...
            'Accelerator','n');
h2 = uimenu('Parent',h1, ...
            'Callback','close(gcf)', ...
            'Label','Exit', ...
            'Tag','NetSett', ...
            'Accelerator','x', ...
            'Separator','on');

% Menu View
h1 = uimenu('Parent',h0, ...
            'Label','View', ...
            'Tag','MenuView');
h2 = uimenu('Parent',h1, ...
            'Callback','fm_pmurep', ...
            'Label','Display results', ...
            'Tag','OTV', ...
            'Accelerator','d');
h2 = uimenu('Parent',h1, ...
            'Callback','fm_tviewer', ...
            'Label','Select text viewer', ...
            'Tag','NetSett', ...
            'Accelerator','t', ...
            'Separator','on');

h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color03, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color10, ...
               'Position',[0.056787     0.45907     0.25762      0.3968], ...
               'String',PMU.voltage, ...
               'Style','listbox', ...
               'Tag','ListboxV', ...
               'Value',1);
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color03, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color10, ...
               'Position',[0.36842      0.4573     0.25762     0.39858], ...
               'String',PMU.angle, ...
               'Style','listbox', ...
               'Tag','ListboxANG', ...
               'Value',1);
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color02, ...
               'Callback','close(gcf);', ...
               'Position',[0.76039     0.19217     0.17452    0.075174], ...
               'String','Close', ...
               'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color03, ...
               'Callback','fm_pmuloc;', ...
               'FontWeight','bold', ...
               'ForegroundColor',Theme.color09, ...
               'Position',[0.76039     0.28648     0.17452    0.075174], ...
               'String','PMU Location', ...
               'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color03, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color06, ...
               'Position',[0.67867      0.4573     0.25762     0.39858], ...
               'String',PMU.location, ...
               'Style','listbox', ...
               'Tag','ListboxPMV', ...
               'Value',1);
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color01, ...
               'HorizontalAlignment','left', ...
               'Position',[0.056787     0.87367     0.24931    0.046263], ...
               'String','Estimated V:', ...
               'Style','text', ...
               'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color01, ...
               'HorizontalAlignment','left', ...
               'Position',[0.36842     0.87367     0.21884    0.046263], ...
               'String','Estimated Theta:', ...
               'Style','text', ...
               'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color01, ...
               'HorizontalAlignment','left', ...
               'Position',[0.67867     0.87367     0.21884    0.046263], ...
               'String','PMU Bus Location:', ...
               'Style','text', ...
               'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color03, ...
               'Position',[0.056787     0.18505     0.40028     0.19217], ...
               'Style','frame', ...
               'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'Position',[0.090028     0.30783     0.25485    0.035587], ...
               'String','# Measured Voltage', ...
               'Style','text', ...
               'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'Position',[0.090028     0.25801     0.25485    0.035587], ...
               'String','# Measured Current', ...
               'Style','text', ...
               'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'Position',[0.090028     0.20996     0.25485    0.035587], ...
               'String','# Pseudo-Measured Current', ...
               'Style','text', ...
               'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color07, ...
               'HorizontalAlignment','left', ...
               'Position',[0.35042     0.30783    0.083102    0.035587], ...
               'String',num2str(PMU.measv), ...
               'Style','text', ...
               'Tag','StaticTextMV');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color07, ...
               'HorizontalAlignment','left', ...
               'Position',[0.35042     0.25801    0.083102    0.035587], ...
               'String',num2str(PMU.measc), ...
               'Style','text', ...
               'Tag','StaticTextMC');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color07, ...
               'HorizontalAlignment','left', ...
               'Position',[0.35042     0.20996    0.083102    0.035587], ...
               'String',num2str(PMU.pseudo), ...
               'Style','text', ...
               'Tag','StaticTextPMC');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'Callback','PMU.method = get(gcbo,''Value'');', ...
               'ForegroundColor',Theme.color05, ...
               'Position',[0.49307     0.30071     0.22992    0.035587], ...
               'String',loc_method, ...
               'Style','popupmenu', ...
               'Tag','PopupMenu1', ...
               'Value',PMU.method);
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color01, ...
               'HorizontalAlignment','left', ...
               'Position',[0.49307     0.34164     0.22992    0.035587], ...
               'String','Location Method:', ...
               'Style','text', ...
               'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'ForegroundColor',Theme.color03, ...
               'FontAngle','italic', ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color05, ...
               'Position',[0.056787    0.051601     0.87812    0.049822], ...
               'Style','frame', ...
               'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'ListboxTop',0, ...
               'Position',[0.33934    0.060498    0.054017    0.030249], ...
               'String',num2str(PMU.number), ...
               'Style','text', ...
               'Tag','StaticTextPMU');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color07, ...
               'HorizontalAlignment','left', ...
               'Position',[0.11219    0.060498     0.20637    0.030249], ...
               'String','Actual PMU Number:', ...
               'Style','text', ...
               'Tag','StaticText4');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'Position',[0.82687    0.060498    0.054017    0.030249], ...
               'String',num2str(PMU.noobs), ...
               'Style','text', ...
               'Tag','StaticTextNOB');
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color04, ...
               'FontName',Theme.font01, ...
               'ForegroundColor',Theme.color07, ...
               'HorizontalAlignment','left', ...
               'Position',[0.46399    0.060498     0.35042    0.030249], ...
               'String','Number of non-observable buses:', ...
               'Style','text', ...
               'Tag','StaticText4');

h1 = uicontrol('Parent',h0, ...
               'CData', fm_mat('pmu_report'), ...
               'Units', 'normalized', ...
               'Callback','fm_pmurep', ...
               'BackgroundColor',Theme.color02, ...
               'Position',[0.49307     0.18861     0.0623    0.0854], ...
               'TooltipString','PMU Placement Report File', ...
               'Tag','Checkbox1');
h1 = uicontrol('Parent',h0, ...
               'CData', fm_mat('pmu_ytree'), ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color02, ...
               'Callback','fm_xy ytree', ...
               'Position',[0.5769    0.18861    0.0623    0.0854], ...
               'TooltipString','Tree of Network Topology', ...
               'Tag','Pushbutton2');
h1 = uicontrol('Parent',h0, ...
               'CData', fm_mat('pmu_etree'), ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color02, ...
               'Callback','fm_xy etree', ...
               'Position',[0.6607    0.18861    0.0623    0.0854], ...
               'TooltipString','Elimination Tree of Network Topology', ...
               'Tag','Pushbutton2');

if nargout > 0, fig = h0; end
